package com.atqinke.designpattern.behavioraltype.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @BelongsProject: BasicConnection
 * @BelongsPackage: com.atqinke.designpattern.behavioraltype.observer
 * @Author: NieHk
 * @CreateTime: 2022-08-29  12:34
 * @Description: 具体被观察者,里面存储了订阅该公众号的用户，并实现了抽象主题中的方法
 * @Version: 1.0
 */
public class OfficialAccount implements Subject {
    //储存订阅公众号的用户
    private List<Observer> Userlist = new ArrayList<Observer>();

    @Override
    public void attach(Observer observer) {
        Userlist.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        Userlist.remove(observer);
    }

    @Override
    public void notify(String message) {
        for (Observer observer : Userlist) {
            observer.update(message);
        }
    }
}
